package org.jeecg.modules.manager.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.manager.entity.OrderGroup;
import org.jeecg.modules.manager.entity.OrderGroupSaleVo;
import org.jeecg.modules.manager.entity.SaleOrder;
import org.jeecg.modules.manager.service.ISaleOrderService;
import java.util.Date;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Description: 销售订单表
 * @Author: jeecg-boot
 * @Date:   2021-11-19
 * @Version: V1.0
 */
@Slf4j
@Api(tags="销售订单表")
@RestController
@RequestMapping("/manager/saleOrder")
public class SaleOrderController extends JeecgController<SaleOrder, ISaleOrderService> {
	@Autowired
	private ISaleOrderService saleOrderService;

	/**
	 *
	 * @param
	 * @return
	 */
	@AutoLog(value = "销售订单表-添加或修改")
	@ApiOperation(value="销售订单表-添加或修改", notes="销售订单表-添加或修改")
	@PostMapping(value = "/addOrEdit")
	public Result<?> addOrEdit(@RequestBody OrderGroupSaleVo orderGroup) {
		return saleOrderService.addOrEdit(orderGroup,currentUser())==1 ? Result.OK("添加成功！") : Result.error("添加失败");
	}


	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "销售订单表-通过id删除")
	@ApiOperation(value="销售订单表-通过id删除", notes="销售订单表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {

		return saleOrderService.removeAllById(id,currentUser()) == 0 ? Result.OK("删除成功!") : Result.error("删除失败");
	}
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "销售订单表-通过id删除订单")
	@ApiOperation(value="销售订单表-通过id删除一个销售订单", notes="销售订单表-通过id删除一个销售订单")
	@DeleteMapping(value = "/deleteOrder")
	public Result<?> deleteOrder(@RequestParam(name="id",required=true) String id) {
		return Result.OK(saleOrderService.removeOrderById(id,currentUser()));
	}


	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "销售订单表-通过id查询")
	@ApiOperation(value="销售订单表-通过id查询", notes="销售订单表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		return Result.OK(saleOrderService.queryById(id));
	}

  /**
   * 导出excel
   *
   * @param request
   * @param saleOrder
   */
  @RequestMapping(value = "/exportXls")
  public ModelAndView exportXls(HttpServletRequest request, SaleOrder saleOrder) {
      return super.exportXls(request, saleOrder, SaleOrder.class, "销售订单表");
  }

  /**
   * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      return super.importExcel(request, response, SaleOrder.class);
  }

}
